﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================

using DevExpress.XtraSplashScreen;
using System;

namespace XCI.Helper
{
    /// <summary>
    /// 闪屏管理
    /// </summary>
    public static class SplashScreenHelper
    {
        /// <summary>
        /// 闪屏对象类型
        /// </summary>
        public static Type SplashScreenType { get; private set; }

        /// <summary>
        /// 设置闪屏对象类型
        /// </summary>
        /// <param name="splashScreenType">闪屏对象类型</param>
        public static void SetSplashScreenType(Type splashScreenType)
        {
            SplashScreenType = splashScreenType;
        }

        /// <summary>
        /// 显示闪屏
        /// </summary>
        /// <param name="msg">消息内容</param>
        public static void Show(string msg)
        {
            if (SplashScreenType == null) return;

            if (SplashScreenManager.Default == null)
            {
                SplashScreenManager.ShowForm(null, SplashScreenType, false, false, false);
            }

            if (!string.IsNullOrEmpty(msg) && SplashScreenManager.Default != null)
            {
                SplashScreenManager.Default.SendCommand(SplashCommand.ShowMessage, msg);
            }
        }

        /// <summary>
        /// 关闭闪屏
        /// </summary>
        public static void Hide()
        {
            SplashScreenManager.CloseForm(false);
        }
    }

    /// <summary>
    /// 闪屏命令类型
    /// </summary>
    public enum SplashCommand
    {
        /// <summary>
        /// 显示消息
        /// </summary>
        ShowMessage
    }
}